package com.su.edu.application.service.impl;

import com.su.edu.application.converter.UserDtoConverter;
import com.su.edu.domain.model.UserDo;
import com.su.edu.application.model.UserDto;
import com.su.edu.domain.service.UserDomainService;
import com.su.edu.application.service.UserService;
import com.su.edu.infra.repository.UserRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author wangjun
 * @since 2024/6/5 14:12
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserDomainService userDomainService;

    @Resource
    private UserDtoConverter userDtoConverter;

    @Resource
    private UserRepository userRepository;

    @Override
    public UserDto findById(Long id) {
        UserDo userDo = userRepository.findById(id);
        return userDtoConverter.toDto(userDo);
    }

    @Override
    public void addUser(UserDto userDto) {
        UserDo userDo = userDtoConverter.toDo(userDto);
        userDomainService.saveUser(userDo);
    }

    @Override
    public void modifyUser(UserDto userDto) {
        UserDo userDo = userDtoConverter.toDo(userDto);
        userDomainService.modifyUser(userDo);
    }
}
